<template>
    <div>
        <basic-container>
            <el-form ref="searchForm" :model="searchForm" size="mini" :inline="true">
                <el-form-item label="审批状态:">
                    <el-select v-model="searchForm.state" placeholder="请选择">
                        <el-option label="全部" value="-1"></el-option>
                        <el-option v-for="(item) in stateData" :label="item.label" :value="item.value"></el-option>
                    </el-select>
                </el-form-item>
                <!--<el-form-item label="申请时间:">
                    <el-date-picker v-model="searchForm.searchDate" type="daterange"
                                    range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item>-->
                <el-form-item>
                    <el-button type="primary" size="small"  plain @click.stop="searchFormSubmit()">搜索</el-button>
                    <el-button size="small"  plain @click.stop="searchFormReset()">重置</el-button>
                </el-form-item>
            </el-form>
            <avue-crud :option="tabOption" :data="tebData" :table-loading="tebLoading" :page="tebDataPage" ref="crud"
                       @size-change='sizeChange'
                       @current-change="currentPage">
                <template slot-scope="scope" slot="state">
                    {{stateDataS[scope.row.state]}}<el-button type="info" plain size="mini" @click.stop="processBtn(scope.row)">流程</el-button>
                </template>
                <template slot-scope="scope" slot="menuLeft">
                    <el-button type="primary" size="small"  plain @click.stop="addModeBtn">添加</el-button>
                </template>
                <template slot-scope="scope" slot="menu">
                    <el-button type="primary" size="small" v-if="scope.row.state == 1 || scope.row.state == 2" plain @click.stop="examineMenuBtn(scope.row,scope.index)">审核</el-button>
                    <el-button type="primary" size="small" plain @click.stop="seeMenuBtn(scope.row,scope.index)">查看</el-button>
                    <el-button type="primary" size="small" v-if="scope.row.state == 1" plain @click.stop="revokeMenuBtn(scope.row,scope.index)">撤销</el-button>
                    <el-button type="primary" size="small" v-if="scope.row.state == 0" plain @click.stop="updMenuBtn(scope.row,scope.index)">修改</el-button>
                    <el-button type="primary" size="small" v-if="scope.row.state == 0" plain @click.stop="delMenuBtn(scope.row,scope.index)">删除</el-button>
                </template>
            </avue-crud>
        </basic-container>

        <!-- 备注 -->
        <el-dialog title="备注" :visible.sync="processMode" width="35%">
            <div class="block">
                <ul class="el-timeline is-reverse">
                    <li class="el-timeline-item"
                        v-for="item in processModeData"
                        :key="item.id">
                        <div class="el-timeline-item__tail"></div>
                        <div class="el-timeline-item__node el-timeline-item__node--normal el-timeline-item__node--"></div>
                        <div class="el-timeline-item__wrapper">
                            <el-card>
                                <div class="el-timeline-item__content">
                                    <div>
                                        审批人：{{item.dealerName}} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <span v-if="item.dealType == 0">未提交</span>
                                        <span v-else-if="item.dealType == 1">不通过</span>
                                        <span v-else-if="item.dealType == 2">通过</span>
                                    </div>
                                    <div>{{item.dealDate}}</div>
                                </div>
                                <h4>{{validatenull(item.dealNote)?"(无审批备注)":item.dealNote}}</h4>
                            </el-card>
                        </div>
                    </li>
                </ul>
            </div>
        </el-dialog>

        <!-- 添加退货 -->
        <el-dialog title="退货单" :visible.sync="addMode" width="75%" center class="addModeClass">
            <el-form ref="addModeForm" :model="addModeForm"  :rules="addModeFormRules" label-width="90px" size="mini" class="addModeFormClass">
                <el-form-item label="备  注:" prop="note">
                    <el-input v-model="addModeForm.note"  type="textarea" maxlength="50" :autosize="{ minRows: 1, maxRows: 1}" placeholder="最多可输入50字"></el-input>
                </el-form-item>
            </el-form>

            <div class="totalSum">
                总金额：{{addModeForm.totalSum}} 元
            </div>

            <avue-crud class="customForm" @selection-change="addModeTabSelectChange" :option="addModeTabOption"
                       :data="addModeTabData" :table-loading="addModeTabLoading" ref="addModeTabData">
                <template slot-scope="scope" slot="num">
                    <el-input @change="inputNum(scope)" v-model="scope.row.num" size="mini" :oninput="oninputNum" :min="0" type="number" placeholder="请输入"></el-input>
                </template>
                <template slot-scope="scope" slot="price">
                    <el-input @change="inputNum(scope)" v-model="scope.row.price" size="mini" :min="0" type="number" placeholder="请输入"></el-input>
                </template>
                <template slot-scope="scope" slot="batch">
                    <el-input v-model="scope.row.batch" type="number" size="mini" placeholder="请输入"></el-input>
                </template>
                <template slot-scope="scope" slot="productionUnit">
                    <el-input v-model="scope.row.productionUnit" size="mini" placeholder="请输入"></el-input>
                </template>
                <template slot-scope="scope" slot="productionTime">
                    <el-date-picker  v-model="scope.row.productionTime" size="mini" type="date" placeholder="选择日期">
                    </el-date-picker>
                </template>
                <template slot-scope="scope" slot="overdueTime">
                    <el-date-picker  v-model="scope.row.overdueTime" size="mini" type="date" placeholder="选择日期">
                    </el-date-picker>
                </template>
                <template slot-scope="scope" slot="menuLeft">
                    <el-button type="primary" size="small"  plain @click.stop="selectGoodsBtn()">选择物品</el-button>
                    <el-button type="primary" size="small"  plain @click.stop="addModeDelMenuBtn(scope.row)">删除</el-button>
                    <el-form size="mini">
                        <el-form-item>
                            <el-input v-model='barcode' @keyup.enter.native="barCodeSearch()" placeholder="使用条形码添加商品"></el-input>
                        </el-form-item>
                    </el-form>
                </template>
            </avue-crud>

            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="addMode = false">关  闭</el-button>
                <el-button size="small" @click="addModePreservation()">保  存</el-button>
                <el-button size="small" type="primary" @click="addModePreservationSubmit()">提  交</el-button>
            </span>
        </el-dialog>

        <!-- 添加选择物品 -->
        <el-dialog title="选择物品" :visible.sync="addModeSelectMode" width="60%" center  class="addModeClass">
            <el-col :span="24">
                <el-form ref="tableOptionSearch" :model="addModeSelectModeForm" size="mini" :inline="true">
                    <el-form-item label="仓库:">
                        <el-select v-model="addModeSelectModeForm.warehouseId" placeholder="请选择">
                            <el-option label="全部" value="-1"></el-option>
                            <el-option v-for="(item) in warehouseData" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="批次号:" label-width="80px">
                        <el-input v-model="addModeSelectModeForm.batch" placeholder="请输入批次号"></el-input>
                    </el-form-item>
                    <el-form-item  label-width="20px">
                        <el-button type="primary" @click="addModeSelectModeSearch()">搜索</el-button>
                    </el-form-item>
                </el-form>
            </el-col>

            <avue-crud :option="addModeSelectModeTabOption" :data="addModeSelectModeTabData" :table-loading="addModeSelectModeTabLoading"
                       :page="addModeSelectModeTabpage" @selection-change="ddModeSelectModeTabSelectionChange">
                <template slot-scope="scope" slot="goodsTypeInfocoded">
                    {{scope.row.goodsTypeInfo.coded}}
                </template>
                <template slot-scope="scope" slot="goodsTypeInfoname">
                    {{scope.row.goodsTypeInfo.name}}
                </template>
                <template slot-scope="scope" slot="goodsTypeInfospecs">
                    {{scope.row.goodsTypeInfo.specs}}
                </template>
                <template slot-scope="scope" slot="goodsTypeInfounit">
                    {{scope.row.goodsTypeInfo.unit}}
                </template>
            </avue-crud>

            <span slot="footer" class="dialog-footer">
                <el-button size="small " @click="addModeSelectMode = false">取 消</el-button>
                <el-button size="small " type="primary" @click="addModeSelectModeBtn()">添  加</el-button>
            </span>
        </el-dialog>

        <!-- 入库单 -->
        <el-dialog title="入库单" ref="examineMode" :visible.sync="examineMode" width="70%" center class="examineModeClass">
            <el-row><el-col :span="6">审批单号：{{examineModeData.coded}}</el-col><el-col :span="6">申请人：{{examineModeData.applyUserInfoName}}</el-col>
                <el-col :span="6">申请时间：{{examineModeData.purchasingDate}}</el-col></el-row>
            <el-row><el-col :span="24">备注：{{examineModeData.note}}</el-col></el-row>

            <avue-crud v-show="examineModeType != 3" class="examineCustomForm" :option="examineModeTabOption" :data="examineModeData.sendBackInfoList"
                       :table-loading="examineModeTabLoading">
                <template slot-scope="scope" slot="menuRight">
                    <span>总金额：{{examineModeData.totalPrice}} 元</span>
                </template>
                <template slot-scope="scope" slot="batch">
                    {{scope.row.dangerousGoods.batch}}
                </template>
                <template slot-scope="scope" slot="producers">
                    {{scope.row.dangerousGoods.producers}}
                </template>
                <template slot-scope="scope" slot="coded">
                    {{scope.row.goodsTypeInfo.coded}}
                </template>
                <template slot-scope="scope" slot="name">
                    {{scope.row.goodsTypeInfo.name}}
                </template>
                <template slot-scope="scope" slot="warehouseName">
                    {{scope.row.warehouse.name}}
                </template>
                <template slot-scope="scope" slot="supplierName">
                    {{scope.row.supplier.name}}
                </template>
                <template slot-scope="scope" slot="specs">
                    {{scope.row.goodsTypeInfo.specs}}
                </template>
                <template slot-scope="scope" slot="goodSnum">
                    {{scope.row.dangerousGoods.num}}
                </template>
                <template slot-scope="scope" slot="unit">
                    {{scope.row.goodsTypeInfo.unit}}
                </template>
                <template slot-scope="scope" slot="goodSprice">
                    {{scope.row.dangerousGoods.price}}
                </template>
            </avue-crud>

            <avue-crud ref="examineModeTab2"  @selection-change="examineModeTabSelectionChange" v-show="examineModeType == 3" class="examineModeTabData2Class" :option="examineModeTabOption2"
                       :data="examineModeData.outPutInfoList" :table-loading="examineModeTabLoading" :page="examineModeDataPage">
                <template slot-scope="scope" slot="sbname">
                    <el-input size="mini" type="number" placeholder="请输入"></el-input>
                </template>
                <template slot-scope="scope" slot="menuLeft">
                    <el-form ref="addModeForm" :model="addModeForm"  :rules="addModeFormRules" :inline="true" size="mini">
                        <el-form-item label="条码号:" >
                            <el-input v-model="addModeForm.remarks" placeholder="请输入条码号"></el-input>
                        </el-form-item>
                        <el-form-item label="物品编码:">
                            <el-input v-model="addModeForm.remarks" placeholder="请输入物品编码"></el-input>
                        </el-form-item>
                        <el-form-item label="名称:">
                            <el-input v-model="addModeForm.remarks" placeholder="请输入名称"></el-input>
                        </el-form-item>
                        <el-form-item label="批次号:" prop="remarks">
                            <el-input v-model="addModeForm.remarks" placeholder="请输入批次号"></el-input>
                        </el-form-item>
                    </el-form>
                </template>
                <template slot="tip">

                    <el-button size="small" type="text" @click="examineModeTab2Select(true)">全 选</el-button>
                    <el-button size="small" type="text" @click="examineModeTab2Select(false)">反 选</el-button>
                </template>
            </avue-crud>

            <!--<el-row v-show="examineModeType == 2"><el-col :span="6">审批状态：XXXXXXXXX</el-col><el-col :span="6">审  批 人：XXXXXXXXX</el-col><el-col :span="6">审批时间：XXXXXXXXX</el-col></el-row>
            <el-row v-show="examineModeType == 2"><el-col :span="24">备注：XXXXXXXXX</el-col></el-row>-->

            <span slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button v-show="examineModeType == 1 && (examineModeData.state == 1 || examineModeData.state == 2)"
                           size="small" @click="examineModeBtn(false)">不通过</el-button>
                <el-button v-show="examineModeType == 1 && (examineModeData.state == 1 || examineModeData.state == 2)"
                           size="small" type="primary" @click="examineModeBtn(true)">通  过</el-button>
                <!-- <el-button v-show="examineModeType == 2" size="small" type="primary" @click="examineMode = false">打印</el-button>-->
                <el-button v-show="examineModeType == 2 && examineModeData.state == 0" size="small" type="primary" @click="addModePreservationSubmit()">提交</el-button>
                <el-button size="small" @click="examineMode = false">关  闭</el-button>
            </span>
        </el-dialog>

        <!-- 审核 -->
        <el-dialog title="审核"
                   :visible.sync="examineModeState.mode"
                   width="30%"
                   center
                   class="examineModeClass">
            <el-form ref="addModeForm"
                     :model="examineModeState.form"
                     :rules="addModeFormRules"
                     label-width="80px"
                     size="mini">
                <el-form-item label="备  注:"
                              prop="remarks">
                    <el-input type="textarea"
                              maxlength="100"
                              :autosize="{ minRows: 4, maxRows: 10}"
                              v-model="examineModeState.form.remarks"
                              placeholder="最多可输入100字"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer" style="text-align: center;">
            <el-button size="small"
                       @click="examineModeState.mode = false">关 闭</el-button>
            <el-button size="small"
                       type="primary"
                       @click="submitExamineModeBtn">{{examineModeState.name}}</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
    import { mapState, mapActions } from 'vuex'
    import { tabOption ,addModeTabOption , addModeSelectModeTabOption,examineModeTabOption,
        addModeSelectCgdModeTabOption,examineModeTabOption2} from "@/const-personal/dangerous/consumablesMining/returnGoods.js"
    import { validatenull ,validatenum ,validatenumord} from '@/util/validate'
    import excel from '@/util/excel'
    import { getDangerousPurchasing } from "@/api/consumables/consumablesMining/purchase"
    import { DepartmentTreeVChildrenNull ,formatDate} from '@/util/util'
    import { getDangerousType, getDangerousDetailed ,getGoodsTypeInfo} from "@/api/consumables/consumablesMining/purchase"
    import { getListWarehouseAll } from "@/api/public/warehouse.js"
    import { getListDangerousInventory, getDangerousInventory, addDangerousInventory, updDangerousInventory, delDangerousInventory ,
        delDangerousSubmission, delDangerousToExamine, delDangerousRevoke ,approvalDangerousRevoke,getDangerousGoods } from "@/api/consumables/consumablesMining/returnGoods"
    import { getSupplierAll } from "@/api/sysSetup/supplierManage";

    export default {
        data(){
            return {
                barcode:'',
                barcodeType:false,
                processModeData:[],
                supplierType:[],
                stateData:[{label: '未提交',value:'0'},
                    {label: '已提交',value:'1'},
                    {label: '审核中',value:'2'},
                    {label: '不通过',value:'3'},
                    {label: '通过',value:'4'}],
                stateDataS:[ '未提交','已提交','审核中','不通过', '通过'],
                warehouseData: [],
                oninputNum:"if(this.value=='00'){this.value='0';}else{this.value=this.value.replace(/[^0-9]/g,'')}",
                dangerousTypeAll: [],//所以危险品类型
                //表格结构
                tabOption:tabOption,
                addModeTabOption:addModeTabOption,
                addModeSelectCgdModeTabOption:addModeSelectCgdModeTabOption,
                addModeSelectModeTabOption:addModeSelectModeTabOption,
                examineModeTabOption:examineModeTabOption,
                examineModeTabOption2:examineModeTabOption2,
                //表格数据
                tebData: [{
                    name: '测试'
                }],
                addModeTabData:[],
                examineModeTabData:[],
                examineModeTabData2:[],
                addModeSelectModeTabData:[],
                //表格等待
                tebLoading:false,
                addModeTabLoading:false,
                addModeSelectModeTabLoading:false,
                examineModeTabLoading:false,
                //表格分页
                tebDataPage: {
                    total: 0, //总页数
                    currentPage: 1, //当前页数
                    pageSize: 10 , //每页显示多少条
                    pageSizes: [5,10,20] //显示多少条数据
                },
                addModeTabDataPage:{
                    total: 0, //总页数
                    currentPage: 1, //当前页数
                    pageSize: 10 , //每页显示多少条
                    pageSizes: [5,10,20] //显示多少条数据
                },
                addModeSelectModeTabpage:{
                    total: 0, //总页数
                    currentPage: 1, //当前页数
                    pageSize: 10 , //每页显示多少条
                    pageSizes: [5,10,20] //显示多少条数据
                },
                examineModeDataPage:{
                    total: 0, //总页数
                    currentPage: 1, //当前页数
                    pageSize: 10 , //每页显示多少条
                    pageSizes: [5,10,20] //显示多少条数据
                },
                //搜索表单数据
                searchForm: {
                    state : '-1',
                    /* warehouseId:'-1',
                     supplierId:'-1',
                     wareState: '-1',*/
                    searchDate:[],
                },
                //添加表单数据
                addModeForm:{
                    totalSum: 0,
                    state: null,
                    warehouseId: null ,
                    supplierId: null,
                    note: null ,
                },
                //添加模态框选中数据
                addModeSelectionList:[],
                //入库单选中数据
                examineModeTabSelectioList:[],
                //添加表单筛选设备
                addModeSelectModeForm: {
                    type:['-1'],
                    coded:null,
                    name:null,
                    warehouseId:'-1'
                },
                //添加表单筛选设备
                addModeSelectCgdModeFrom: {

                },
                //添加表单验证
                addModeFormRules:{
                    /*state:[{required: true,message: "请选择入库类型",trigger: 'change'}],
                    warehouseId:[{required: true,message: "请选择仓库",trigger: 'change'}],
                    supplierId:[{required: true,message: "请选择供应商",trigger: 'change'}],*/
                    note:[{required: true,message: "请输入备注",trigger: 'change'}],
                },
                //流程模态框
                processMode : false,
                //添加模态框
                addMode: false,
                examineMode:false,
                examineModeData:{
                    supplier:{},
                    warehouse:{},
                    wareState:0,
                    state:0,
                    outPutInfoList:[],
                },
                //添加选择设备
                addModeSelectMode:false,
                //添加选择设备
                addModeSelectCgdMode:false,
                //采购单模态框状态
                examineModeType: 0,
                //流程数据
                activities: [{
                    content: '活动按期开始',
                    timestamp: '2018-04-15'
                }, {
                    content: '通过审核',
                    timestamp: '2018-04-13'
                }, {
                    content: '创建成功',
                    timestamp: '2018-04-11'
                }],
                //树状图数据
                treeData:[
                    {
                        id:0,
                        label:'一级部门',
                        value:0,
                        children:[
                            {
                                id:1,
                                label:'一级部门1',
                                value:0,
                            }
                        ]
                    }],
                addModeSelectCgdModeSelectList:[],
                ddModeSelectModeTabSelectionChangeList:[],
                addModeData:{},
                examineModeState: {
                    mode: false,
                    form: {
                        remarks: ''
                    }
                },
            }
        },
        created(){
            this.searchFormSubmit()
            this.dangerousType()
            this.getWarehouseData()
            this.getSupplierAllData()
        },
        watch:{
            'addModeForm.totalSum':{
                handler(val){
                    this.addModeForm.totalSum = Number(val).toFixed(2)
                }
            },
            barcode: function (newQuestion, oldQuestion) {
                if(this.barcodeType){
                    this.barcodeType = false
                    this.barcode = newQuestion.substr(oldQuestion.length,newQuestion.length)
                }
            }
        },
        methods: {
            examineModeBtn (state) {
                this.examineModeState = {
                    mode: true,
                    name: state ? '通 过' : '不通过',
                    id: this.examineModeData.id,
                    status: state ? 1 : 0,
                    form: {
                        remarks: ''
                    }
                }
            },
            barCodeSearch(){
                let params = {
                    barcode:this.barcode,
                    page: 1,
                    size: 10,
                }
                getDangerousGoods(params).then(res => {
                    if(res.data.code == 200 && res.data.data.list.length > 0) {
                        res.data.data.list.forEach(item=>{
                            let data  = item;
                            data.goodsTypeInfoId = item.goodsTypeInfo.id
                            data.warehouseName = item.warehouse.name;
                            data.warehouseId = item.warehouse.id;
                            data.supplierName = item.supplier.name;
                            data.supplierId = item.supplier.id;
                            data.specs = item.goodsTypeInfo.specs;
                            data.coded = item.goodsTypeInfo.coded;
                            data.name = item.goodsTypeInfo.name;
                            data.unit = item.goodsTypeInfo.unit
                            data.producers = item.producers;
                            data.goodSprice= item.price
                            data.goodSnum = item.num;
                            data.batch = item.batch;
                            data.totalNum = 0.0;
                            data.price = 0.0;
                            data.num = 0.0;
                            this.addModeTabData.push(data)
                        })
                    } else {
                        this.$notify.error({ title: '查询失败', message: '该物品不存在！', type: 'danger', });
                    }
                    this.barcodeType = true
                })
            },

            submitExamineModeBtn () {
                let data = {
                    id: this.examineModeState.id,
                    status: this.examineModeState.status,
                    remarks: this.examineModeState.form.remarks
                }
                delDangerousToExamine(data).then(res => {
                    if (res.data.code == 200) {
                        this.$notify({ title: '操作成功', type: 'success', message: '审核成功!' });
                        this.examineMode = false;
                        this.examineModeState.mode = false;
                        this.searchFormSubmit()
                    } else {
                        this.$notify.error({ title: '操作失败', message: res.data.message, type: 'danger', });
                    }
                })
            },
            getSupplierAllData(){
                getSupplierAll().then(res =>{
                    if(res.data.code==200){
                        this.supplierType = res.data.data
                    } else {
                        this.$notify.error({ title: '查询失败', message: '获取供应商数据失败！', type: 'danger', });
                    }
                })
            },
            inputNum(scope){
                let data = JSON.parse(JSON.stringify(this.addModeTabData));
                data[scope.row.$index].totalNum = (scope.row.num * scope.row.price).toFixed(2)
                this.addModeTabData = data
                this.addMmodeCalculation()
            },
            addMmodeCalculation(){
                this.addModeForm.totalSum = 0;
                this.addModeTabData.forEach(item=>{
                    this.addModeForm.totalSum += Number(item.totalNum)
                })
            },
            addModeBtn(){
                this.addMode = true
                this.addModeForm = {
                    totalSum: 0
                }
                this.addModeData = {}
                this.addModeTabData = []
                try {
                    this.$refs.addModeForm.resetFields();
                } catch (e) { }
            },
            addModeTabSelectChange(list){
                this.addModeSelectionList = list
            },
            addModePreservation(){
                this.$refs['addModeForm'].validate((valid)=>{
                    if(!valid){
                        return
                    } else if(this.validateFormNull()){
                        return
                    } else{
                        if(validatenull(this.addModeForm.id)){
                            addDangerousInventory(this.addModeData).then(res =>{
                                if (res.data.code === 200) {
                                    this.addModeData.id = res.data.data.id
                                    this.$notify({title: '操作成功', type: 'success', message: '添加成功,请提交!'});
                                    this.searchFormSubmit()
                                } else {
                                    this.$notify.error({title: '操作失败', type: 'danger', message: res.data.message});
                                }
                            })
                        } else {
                            updDangerousInventory(this.addModeData).then(res =>{
                                if (res.data.code === 200) {
                                    this.$notify({title: '操作成功', type: 'success', message: '修改成功,请提交!'});
                                    this.searchFormSubmit()
                                } else {
                                    this.$notify.error({title: '操作失败', type: 'danger', message: res.data.message});
                                }
                            })
                        }
                    }
                })
            },
            addModePreservationSubmit(){
                if(!this.addModeData.id){return this.$notify({title: '操作失败', type: 'error', message: '请先保存!'});}
                delDangerousSubmission(this.addModeData.id).then(res =>{
                    if (res.data.code === 200) {
                        this.$notify({title: '操作成功', type: 'success', message: '提交成功!'});
                        this.searchFormSubmit()
                        //成功关闭弹窗
                        this.addMode = false;
                    } else {
                        this.$notify.error({title: '操作失败', type: 'danger', message: res.data.message});
                    }
                })
            },
            validateFormNull(){
                if(validatenull(this.addModeTabData)){
                    this.$notify.error({ title: '操作提示', message: '请选择入库物品！', type: 'danger', });
                    return true
                }
                let outPutInfoList = [];
                for (let i = 0; i < this.addModeTabData.length; i++ ) {
                    let item = this.addModeTabData[i]
                    if(!validatenum(item.num)||item.num==0){
                        this.$notify.error({ title: '操作提示', message: '请输入正确的数量！', type: 'danger', });
                        return true
                    } else if(!validatenumord(item.price)||item.price==0){
                        this.$notify.error({ title: '操作提示', message: '请输入正确的单价！', type: 'danger', });
                        return true
                    } else {
                        outPutInfoList.push({
                            goodsTypeInfoId: item.goodsTypeInfoId,
                            num: Number(item.num),
                            price: Number(item.price),
                            warehouseId: item.warehouseId,
                            supplierId: item.supplierId,
                        })
                    }
                }
                this.addModeData = this.addModeForm
                this.addModeData.sendBackInfoList = outPutInfoList;
                return false
            },
            ...mapActions('equipmentLedger', ['_getSupplierAll']),
            //仓库数据
            getWarehouseData(){
                getListWarehouseAll().then(res =>{
                    if(res.data.code==200){
                        res.data.data.forEach(item=>{
                            this.warehouseData.push({label:item.name,value:item.id})
                        })
                    } else {
                        this.$notify.error({ title: '查询失败', message: '获取仓库数据失败！', type: 'danger', });
                    }
                })
            },
            addModeSelectModeBtn(){
                this.addModeSelectMode = false
                this.ddModeSelectModeTabSelectionChangeList.forEach(item=>{
                    let data  = item;
                    data.goodsTypeInfoId = item.goodsTypeInfo.id
                    data.warehouseName = item.warehouse.name;
                    data.warehouseId = item.warehouse.id;
                    data.supplierName = item.supplier.name;
                    data.supplierId = item.supplier.id;
                    data.specs = item.goodsTypeInfo.specs;
                    data.coded = item.goodsTypeInfo.coded;
                    data.name = item.goodsTypeInfo.name;
                    data.unit = item.goodsTypeInfo.unit
                    data.producers = item.producers;
                    data.goodSprice= item.price
                    data.goodSnum = item.num;
                    data.batch = item.batch;
                    data.totalNum = 0.0;
                    data.price = 0.0;
                    data.num = 0.0;
                    this.addModeTabData.push(data)
                })
            },
            ddModeSelectModeTabSelectionChange(list){
                this.ddModeSelectModeTabSelectionChangeList = list
            },
            dangerousType(){
                getDangerousType().then(res => {
                    if (res.data.code === 200) {
                        this.dangerousTypeAll = DepartmentTreeVChildrenNull(res.data.data,[{label:'全部',value:'-1'}])
                    } else {
                        this.$notify.error(res.data.message)
                    }
                })
            },
            addModeSelectionChange(list){
                this.addModeSelectCgdModeSelectList = list
            },
            //流程
            processBtn(row){
                approvalDangerousRevoke(row.id).then(res=>{
                    if (res.data.code === 200) {
                        this.processModeData = res.data.data ;
                        this.processMode = true;
                    } else {
                        this.$notify.error({title: '操作失败', type: 'danger', message: res.data.message});
                    }
                })
            },
            //删除
            delMenuBtn(row,index){
                this.$confirm('删除后，订单将无法找回, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //请求-删除
                    delDangerousInventory(row.id).then(res=>{
                        if (res.data.code === 200) {
                            this.$notify({title: '操作成功', type: 'success', message: '删除成功!'});
                            this.searchFormSubmit()
                        } else {
                            this.$notify.error({title: '操作失败', type: 'danger', message: res.data.message});
                        }
                    })
                }).catch(() => {
                    this.$notify({ title: '已取消删除', type: 'info', });
                });
            },
            //审核
            examineMenuBtn(row,index){
                this.examineMode = true;
                this.examineModeType = 1;
                this._getDangerousInventory(row.id)
            },
            //查看
            seeMenuBtn(row,index){
                this.examineMode = true;
                this.examineModeType = 2;
                this.addModeData.id = row.id
                this._getDangerousInventory(row.id)
            },
            //修改申请单
            updMenuBtn(row,index){
                this.addMode = true;
                getDangerousInventory(row.id).then(res =>{
                    if(res.data.code==200){
                        this.addModeForm = {
                            id: res.data.data.id ,
                            note: res.data.data.note ,
                            totalSum: res.data.data.totalPrice ,
                        }
                        this.addModeTabData = []
                        res.data.data.sendBackInfoList.forEach(item=>{
                            let data = item.goodsTypeInfo
                            data.warehouseName = item.warehouse.name;
                            data.warehouseId = item.warehouse.id;
                            data.supplierName = item.supplier.name;
                            data.supplierId = item.supplier.id;
                            data.goodsTypeInfoId = item.goodsTypeInfoId;
                            data.num = Number(item.num);
                            data.price = Number(item.price);
                            data.batch = item.dangerousGoods.batch;
                            data.totalNum = Number(item.totalPrice);
                            data.producers = item.dangerousGoods.producers;
                            data.goodSprice= item.dangerousGoods.price
                            data.goodSnum = item.dangerousGoods.num;
                            this.addModeTabData.push(data)
                        })
                        console.log(this.addModeForm)
                    } else {
                        this.$notify.error({ title: '查询失败', message: '获取供应商数据失败！', type: 'danger', });
                    }
                })
            },
            //打印标签
            printingMenuBtn(row,index){
                this.examineMode = true;
                this.examineModeType = 3;
                this._getDangerousInventory(row.id)
            },
            _getDangerousInventory(id){
                getDangerousInventory(id).then(res =>{
                    if(res.data.code==200){
                        this.examineModeData = res.data.data
                    } else {
                        this.$notify.error({ title: '查询失败', message: '获取供应商数据失败！', type: 'danger', });
                    }
                })
            },
            //导出
            exportMenuBtn(row,index){
                let filterTabDatas = this.tebData;
                if (filterTabDatas.length > 0) {
                    const params = {
                        title: ['序号', '物品编号', '物品名称', '规格','库存','将过期/已过期库存','采购数量','单位','单价(元)','总金额(元)'],
                        key: ['id', 'name', 'phone', 'date'],
                        data: filterTabDatas,
                        autoWidth: true,
                        filename: '采购单物品'
                    }
                    excel.export_array_to_excel(params)
                } else {
                    this.$message({
                        type: 'info',
                        message: '请选择要导出的数据'
                    });
                }
            },
            //撤销
            revokeMenuBtn(row,index){
                this.$confirm('撤销后，申请单将变为未提交状态！', '提示', {
                    confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
                }).then(() => {
                    delDangerousRevoke(row.id).then(res=>{
                        if (res.data.code === 200) {
                            this.$notify({title: '操作成功', type: 'success', message: '撤销成功!'});
                            this.searchFormSubmit()
                        } else {
                            this.$notify.error({title: '操作失败', type: 'danger', message: res.data.message});
                        }
                    })
                });
            },
            //删除
            addModeDelMenuBtn(row){
                if(validatenull(this.addModeSelectionList)){
                    this.$notify.error({ title: '操作失败', message: '请选择至少一条数据！', type: 'danger', });
                    return;
                }
                this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
                }).then(() => {
                    //倒叙
                    console.log(this.addModeSelectionList.reverse())
                    this.addModeSelectionList.reverse()
                    console.log(this.addModeSelectionList.reverse())
                    this.addModeSelectionList.forEach(item => {
                        this.$delete(this.addModeTabData, item.$index)
                    })
                    this.$refs['addModeTabData'].toggleSelection(this.addModeTabselectionList);
                    this.$notify({ title: '操作成功', type: 'success', message: '删除成功!'});
                });
            },

            // 切换页面
            currentPage (val) {
                this.tebDataPage.currentPage = val;
                this.searchFormSubmit();
            },
            sizeChange (val) {
                this.tebDataPage.pageSize = val
                this.searchFormSubmit()
            },
            //提交搜索
            searchFormSubmit(){
                let data ={
                    /*  warehouseId: this.searchForm.warehouseId == -1 ? null : this.searchForm.warehouseId,
                      wareState: this.searchForm.wareState == -1 ? null : this.searchForm.wareState,
                      supplierId: this.searchForm.supplierId == -1 ? null : this.searchForm.supplierId,*/
                    state: this.searchForm.state == -1 ? null : this.searchForm.state,
                    startTime: this.searchForm.searchDate.length !=2 ? null : formatDate(this.searchForm.searchDate[0],'yyyy-MM-dd'),
                    endTime: this.searchForm.searchDate.length !=2 ? null : formatDate(this.searchForm.searchDate[1],'yyyy-MM-dd'),
                    page: this.tebDataPage.currentPage,
                    size: this.tebDataPage.pageSize,
                }
                getListDangerousInventory(data).then(res=>{
                    if (res.data.code === 200) {
                        this.tebData = res.data.data.list
                        this.tebDataPage.total = res.data.data.total
                        this.tebDataPage.pageSize = res.data.data.pageSize
                        this.tebDataPage.currentPage = res.data.data.pageNum
                    } else {
                        this.$notify.error({ title: '查询失败', message: '获取数据失败！', type: 'danger', });
                    }
                })
            },
            selectGoodsBtn(){
                this.addModeSelectModeSearch()
                this.addModeSelectMode = true
            },
            addModeSelectModeSearch(){
                let params = {
                    page: this.addModeSelectModeTabpage.currentPage,
                    size: this.addModeSelectModeTabpage.pageSize,
                    batch: this.addModeSelectModeForm.batch,
                    warehouseId: this.addModeSelectModeForm.warehouseId == -1 ? null : this.addModeSelectModeForm.warehouseId,
                }
                getDangerousGoods(params).then(res => {
                    if (res.data.code === 200) {
                        this.addModeSelectModeTabData = res.data.data.list
                        this.addModeSelectModeTabpage.total = res.data.data.total
                        this.addModeSelectModeTabpage.pageSize = res.data.data.pageSize
                        this.addModeSelectModeTabpage.currentPage = res.data.data.pageNum
                    } else {
                        this.$notify.error({ title: '查询失败', message: '获取数据失败！', type: 'danger', });
                    }
                })
            },
            addModeSelectCgdModeSearch(){
                this.selectPurchaseBtn()
            },
            //全选 反选
            examineModeTab2Select(flog){
                if(flog){
                    this.$refs.examineModeTab2.selectClear();
                    this.examineModeTabData2.forEach(item=>{
                        this.$refs.examineModeTab2.toggleRowSelection(item);
                    })
                } else {

                    let selectlis = this.examineModeTabSelectioList.map(item=>item.id);
                    if(selectlis.length>0){
                        this.$refs.examineModeTab2.selectClear();
                        this.examineModeTabData2.forEach(item=>{
                            if(selectlis.indexOf(item.id)==-1) {
                                // console.log(item.id)
                                this.$refs.examineModeTab2.toggleRowSelection(item);
                            }
                        })
                    }else{
                        this.examineModeTabData2.forEach(item=>{
                            this.$refs.examineModeTab2.toggleRowSelection(item);
                        })
                    }
                }
            },
            //清空搜索
            searchFormReset(){
                this.searchForm = {
                    wareState : '-1', //状态
                }
            },
            examineModeTabSelectionChange(list){
                // console.log(list)
                this.examineModeTabSelectioList = list;
            }
        }
    }
</script>

<style>
    .customForm .avue-crud__menu{
        float: left;
        display: inline-block;
        width: auto;
    }
    .customForm .avue-crud__right{
        float:right;
    }
    .customForm .avue-crud__right button{
        margin-right: 0px!important;
        margin-left: 8px!important;
    }
    .customForm .avue-crud__tip{
        margin: 0px;
    }
    .customForm .avue-crud__left{
        display: -webkit-inline-box;
        margin-right: 10px;
    }
    .customForm .avue-crud__tip{
        display: none;
    }
    .addModeClass .avue-crud__tip{
        margin: 0px 0px 8px!important;
    }
    .addModeClass .avue-crud__menu{
        margin-bottom:0px!important;
    }
    .examineModeClass .el-dialog__body{
        padding: 5px 25px 0px!important;
    }
    .examineCustomForm{
        width: 100% !important;
    }
    .addModeSelectCgdModeClass .avue-crud__menu{
        float: right!important;
        display: inline-block!important;
        width: auto;
    }
    .addModeSelectCgdModeClass .el-form-item{
        margin-bottom: 0px!important;
    }
    .addModeSelectCgdModeClass .el-form-item .el-button{
        margin-right:0px!important;
        margin-bottom: 0px!important;
    }
    .addModeSelectCgdModeClass .el-form-item:last-of-type{
        margin-right: 0px!important;
    }
    .addModeSelectCgdModeClass .avue-crud__tip{
        margin-top:0px!important;
    }
    .addModeClass,.examineCustomForm .el-input__inner[type="number"]{
        padding-right:0px!important;
    }
    .addModeClass .el-dialog__body{
        padding-bottom: 0px!important;
    }
    .examineModeClass .el-row{
        margin-left: 0px!important;
    }
    .examineModeTabData2Class .avue-crud__tip{

    }
    .el-input--suffix .el-input__inner {
        padding-right: 20px!important;
    }
    .el-input__inner,input[type="number"]{
        padding-right: 0px!important;
    }
    .totalSum{
        display: inline-block!important;
        float: right!important;
        margin-right: 10px!important;
    }
</style>